package com.zb.app.controller;

import com.zb.app.service.ApUserRealnameService;
import com.zb.model.common.PageResult;
import com.zb.model.common.Result;
import com.zb.model.dto.user.AuthDTO;
import com.zb.model.pojo.user.ApUserRealname;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/auth")
public class ApUserRealnameController {

    @Autowired
    private ApUserRealnameService userRealnameService;

//    根据状态查询实名认证列表
    @GetMapping("/list")
    public Result loadListByStatus(AuthDTO dto){
        if(dto.getStatus() == -1) {
            dto.setStatus(null);
        }
        PageResult pageResult = userRealnameService.pageList(dto);
        return Result.SUCCESS(pageResult);
    }
//    实名认证通过
    @PostMapping("/authPass")
    public Result authPass(@RequestBody AuthDTO DTO) {
        return userRealnameService.updateStatusById(DTO, Short.valueOf("9"));
    }
//    实名认证失败
    @PostMapping("/authFail")
    public Result authFail(@RequestBody AuthDTO DTO) {
        return userRealnameService.updateStatusById(DTO, Short.valueOf("2"));
    }

    //    根据id查询实名认证信息
    @GetMapping("/{id}")
    public Result getRealnameById(@PathVariable Integer id){
        ApUserRealname pageResult = userRealnameService.getById(id);
        return Result.SUCCESS(pageResult);
    }

}
